Warning: package 'broom.mixed' was built under R version 4.3.2
library(grid)
droughtnet <-read_csv("droughtnet_data_cleaned_final.csv", col_types =cols(calluna_shoot_type =col_factor(levels =c("Long", "Short"))),guess_max =Inf)View(droughtnet)# Now, to reorder the ageClass factor levels to start with Pioneerdroughtnet$ageClass <-factor(droughtnet$ageClass, levels =c("Mature", "Pioneer"))levels(droughtnet$ageClass)
[1] "Mature" "Pioneer"
droughtnet2 <- droughtnet %>%mutate(plant_nr =case_when(# For Calluna vulgaris under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Calluna vulgaris"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_CV_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Calluna vulgaris under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Calluna vulgaris"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_CV_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium myrtillus under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium myrtillus"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_VM_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium myrtillus under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium myrtillus"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_VM_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium vitis-idaea under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium vitis-idaea"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_VV_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium vitis-idaea under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium vitis-idaea"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_VV_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Empetrum nigrum under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Empetrum nigrum"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_EN_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Empetrum nigrum under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Empetrum nigrum"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_EN_Ext(90)_", DroughNet_plotID, "_", plant_nr),# Default case if none of the above conditions are metTRUE~as.character(plant_nr) ))view(droughtnet2)
# Specify the columns to check for NA values# List of columns to check for NA valuescolumns_to_check <-c("DroughtTrt", "DroughNet_plotID", "ageClass", "siteID", "species", "plant_height", "SLA", "mean_thickness", "dry_mass_g_original", "LDMC", "leaf_area", "wet_mass_g", "dry_mass_g")# Check for rows with any NA values in the specified columnsna_rows <-apply(droughtnet2[columns_to_check], 1, function(row) any(is.na(row)))# Create a data frame showing how many NA values there are in each rowna_row_summary <- droughtnet2[na_rows, columns_to_check]na_row_summary$row_na_count <-rowSums(is.na(na_row_summary))# Summarize the number of rows by the count of NAs they containna_row_summary <- na_row_summary %>%group_by(row_na_count) %>%summarise(n =n(), .groups ='drop')# Create a summary showing the co-occurrence of NA values across the specified columnsna_co_occurrence <- droughtnet2 %>%summarise(across(all_of(columns_to_check), ~sum(is.na(.)))) %>%pivot_longer(cols =everything(), names_to ="variable", values_to ="na_count") %>%arrange(desc(na_count))# Print the summariesprint(paste("Total rows with any NA values across checked columns:", sum(na_rows)))
[1] "Total rows with any NA values across checked columns: 50"
# Create the new data frame with selected columnsdroughtnet_data2 <-select(droughtnet2, "envelope_ID", "siteID", "species", "ageClass", "DroughtTrt", "DroughNet_plotID", "leaf_age", "calluna_shoot_type", "plant_height", "mean_thickness", "SLA", "LDMC", "plant_nr")view(droughtnet_data2)# Specify the columns to check for NA valuescolumns_to_check2 <-c("plant_height", "mean_thickness", "SLA", "LDMC")# Remove rows with any NA values in the specified columnsdroughtnet_data2_clean <- droughtnet_data2[!rowSums(is.na(droughtnet_data2[columns_to_check2])), ]view(droughtnet_data2_clean)# Calculate the total number of NAs removed (for the specified columns only)# This calculation considers rows removed rather than individual NAstotal_NAs_removed <-nrow(droughtnet_data2) -nrow(droughtnet_data2_clean)# Calculate the total number of entries remainingtotal_entries_remaining <-nrow(droughtnet_data2_clean)# Print out the total NAs removed and total entries remainingcat("Total NAs removed:", total_NAs_removed, "\n")
# Specify the species of interest, including Calluna vulgarisspecies_of_interest <-c("Empetrum nigrum", "Vaccinium myrtillus", "Vaccinium vitis-idaea", "Calluna vulgaris")# Filter the data to include only the specified species where leaf_age is 'young',# and for Calluna vulgaris, additionally check that calluna_shoot_type is 'short'filtered_data <- droughtnet_data2_clean %>%filter(species %in% species_of_interest, leaf_age =="young") %>%filter(# Include Calluna vulgaris from Tjøtta regardless of calluna_shoot_type (species =="Calluna vulgaris"& siteID =="Tjøtta") |# Include Calluna vulgaris from Lygra only if calluna_shoot_type is Short (species =="Calluna vulgaris"& siteID =="Lygra"& calluna_shoot_type =="Short") |# Include other species of interest from both sites (species !="Calluna vulgaris") )view(filtered_data)
p <-ggplot(filtered_data, aes(x =as.factor(plant_nr), y = mean_thickness, color = DroughtTrt)) +geom_point() +# Use geom_point for individual observationsfacet_wrap(~ ageClass + siteID, scales ="free", nrow =2) +# Adjusted for clearer separationtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="thickness Response to Treatment",x ="Plant Number",y ="thickness", # Assuming height is in centimeterscolor ="Drought Treatment") # Adjusted labelggsave("thickness_plot.png", plot = p, width =10, height =8, dpi =300)
plots
plant height
filtered_data <- filtered_data %>%filter(siteID %in%c("Tjøtta", "Lygra"), DroughtTrt %in%c("Amb (0)", "Ext (90)"), ageClass %in%c("Pioneer", "Mature"))ggplot(filtered_data, aes(x = species, y = plant_height, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +# Removed leaf_age from facet_gridtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="Plant Height vs Treatment by Species for Young Leaves",x ="Species",y ="Plant Height") +scale_fill_manual(values =c("Amb (0)"="blue", "Ext (90)"="grey")) # Assigning colors to treatments
SLA
ggplot(filtered_data, aes(x = species, y =log(SLA), fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="SLA vs Treatment by Species",x ="Species",y ="Log (SLA)",fill ="Drought Treatment",caption ="Figure 2: SLA Variation in Dwarf Shrubs Under Drought Conditions Across Different Ages and Sites") +scale_fill_manual(values =c("Amb (0)"="orange", "Ext (90)"="darkgrey")) # Assigning colors to treatments
LDMC
ggplot(filtered_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in dwarf Shrubs Under drought conditions across different successional phases and sites") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue")) # Assigning colors to treatments
#trying using jitter for the graphsggplot(filtered_data, aes(x = species, y = LDMC, color = DroughtTrt)) +geom_jitter(position =position_dodge(width =0.5), size =1.5, alpha =0.7) +# Use position_dodge to separate pointsfacet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # Vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",color ="Drought Treatment", # Updated from fill to colorcaption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases and Sites") +scale_color_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="red")) # Assigning colors to treatments
Mean_thickness
filtered_data <- filtered_data %>%filter(siteID %in%c("Tjøtta", "Lygra"), DroughtTrt %in%c("Amb (0)", "Ext (90)"), ageClass %in%c("Pioneer", "Mature"))ggplot(filtered_data, aes(x = species, y = mean_thickness, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +# Removed leaf_age from facet_gridtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="Plant Height vs Treatment by Species for Young Leaves",x ="Species",y ="mean_thickness") +scale_fill_manual(values =c("Amb (0)"="blue", "Ext (90)"="grey")) # Assigning colors to treatments
Analysis for lygra site
filter data only for lygra
# Filter the data for siteID Lygralygra_data <- filtered_data %>%filter(siteID =="Lygra")view(lygra_data)
Trait 1- LDMC- models
lygra_data$plant_nr <-as.factor(lygra_data$plant_nr)# fitting a linear mixed-effects model using lmer, plant nr is the nested random effect# Ensure variables are treated as categorical if they represent categorieslygra_data$plant_nr <-as.factor(lygra_data$plant_nr)# Model with all the main effects for LDMCLY_model_main_effects_LDMC <-lmer(LDMC ~ species + DroughtTrt + ageClass + (1| DroughNet_plotID/plant_nr),data = lygra_data)summary(LY_model_main_effects_LDMC)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula:
LDMC ~ species + DroughtTrt + ageClass + (1 | DroughNet_plotID/plant_nr)
Data: lygra_data
REML criterion at convergence: 3697.4
Scaled residuals:
Min 1Q Median 3Q Max
-4.0698 -0.4306 0.0023 0.3775 4.6922
Random effects:
Groups Name Variance Std.Dev.
plant_nr:DroughNet_plotID (Intercept) 1706.15 41.306
DroughNet_plotID (Intercept) 7.11 2.667
Residual 1495.66 38.674
Number of obs: 351, groups:
plant_nr:DroughNet_plotID, 125; DroughNet_plotID, 12
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 347.948 9.927 27.836 35.051 < 2e-16 ***
speciesEmpetrum nigrum 24.993 11.850 118.372 2.109 0.03703 *
speciesVaccinium myrtillus 3.750 12.175 119.802 0.308 0.75860
speciesVaccinium vitis-idaea -54.351 11.604 111.583 -4.684 8e-06 ***
DroughtTrtExt (90) 2.925 8.768 9.559 0.334 0.74586
ageClassPioneer 30.709 8.859 9.960 3.466 0.00609 **
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) spcsEn spcsVm spcVv- DTE(90
spcsEmptrmn -0.495
spcsVccnmmy -0.528 0.448
spcsVccvts- -0.553 0.448 0.435
DrghtTE(90) -0.402 0.035 0.102 -0.041
ageClassPnr -0.404 -0.122 -0.081 0.061 -0.090
ggplot(lygra_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +facet_grid(~ ageClass, scales ="free") +# Facet only by ageClasstheme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue"))
#fit model# Get fitted values directly from the modelfitted_values <-predict(LY_LDMC_species_droughtTrt, re.form =NA) lygra_data$fitted <- fitted_values# Assuming fitted_values has been added to filtered_data as shown aboveggplot(lygra_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +geom_point(aes(y = fitted), position =position_dodge(width =0.75), color ="red", size =1.5) +# Add fitted valuesfacet_grid(~ ageClass, scales ="free") +# Facet only by ageClasstheme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # Vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +labs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue"))
#fiiting in the geom jitter plot# Get fitted values directly from the modelfitted_values <-predict(LY_LDMC_species_droughtTrt, re.form =NA) # Assuming 'fitted_values' is a vector of the same length as 'lygra_data'lygra_data$fitted <- fitted_valuesfitted_values$dodge_position <-as.numeric(lygra_data$DroughtTrt) -1.5
Warning: NAs introduced by coercion
Warning in fitted_values$dodge_position <- as.numeric(lygra_data$DroughtTrt) -
: Coercing LHS to a list
ggplot(lygra_data, aes(x = species, y = LDMC, group = DroughtTrt)) +geom_jitter(aes(color = DroughtTrt), position =position_dodge(width =0.5), size =1.5, alpha =0.7) +geom_point(aes(y = fitted, color = DroughtTrt), # Ensure 'fitted' is now recognizedposition =position_dodge(width =0.5), size =3, shape =16, color ="black") +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1)) +labs(title ="LDMC vs Treatment by Species", x ="Species", y ="LDMC", color ="Drought Treatment") +scale_color_manual(values =c("Amb (0)"="darkgreen", "Ext (90)"="deeppink"))
# species * age Class (h2)xxx#this will help adress the hypothesis by examining weather the effect of drought on trait varies between age classes#significant interaction supports the hypothesis that mat and pio respond differently to droght conditions, potentially more consrvative traits in mat than pioLY_LDMC_species_ageClass <-lmer(LDMC ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_LDMC_species_ageClass)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: log(SLA) ~ DroughtTrt * ageClass + (1 | DroughNet_plotID/plant_nr)
Data: lygra_data
REML criterion at convergence: 54
Scaled residuals:
Min 1Q Median 3Q Max
-5.1284 -0.3052 0.0027 0.3149 5.8896
Random effects:
Groups Name Variance Std.Dev.
plant_nr:DroughNet_plotID (Intercept) 0.20359 0.4512
DroughNet_plotID (Intercept) 0.00000 0.0000
Residual 0.02017 0.1420
Number of obs: 351, groups:
plant_nr:DroughNet_plotID, 125; DroughNet_plotID, 12
Fixed effects:
Estimate Std. Error df t value
(Intercept) 4.93140 0.08013 121.49535 61.545
DroughtTrtExt (90) -0.20928 0.12192 121.00630 -1.717
ageClassPioneer -0.12702 0.11321 121.07661 -1.122
DroughtTrtExt (90):ageClassPioneer 0.15801 0.16571 120.77409 0.954
Pr(>|t|)
(Intercept) <2e-16 ***
DroughtTrtExt (90) 0.0886 .
ageClassPioneer 0.2641
DroughtTrtExt (90):ageClassPioneer 0.3422
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) DrTE(90) agClsP
DrghtTE(90) -0.657
ageClassPnr -0.708 0.465
DrTE(90):CP 0.484 -0.736 -0.683
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#plot variance is zero#validate modelperformance::check_model(LY_SLA_droughtTrt_ageclass, detrend =FALSE)
anova(LY_SLA_droughtTrt_ageclass)
Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
DroughtTrt 0.049855 0.049855 1 120.77 2.4721 0.1185
ageClass 0.006772 0.006772 1 120.77 0.3358 0.5633
DroughtTrt:ageClass 0.018336 0.018336 1 120.77 0.9092 0.3422
#xxxxLY_SLA_species__drought_ageClass <-lmer(log(SLA) ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)
Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
species 2.56118 0.85373 3 110.500 53.0792 < 2e-16 ***
DroughtTrt 0.08101 0.08101 1 10.368 5.0367 0.04775 *
species:DroughtTrt 0.00996 0.00332 3 110.500 0.2064 0.89177
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
# species * age Class (h2)LY_height_species_ageClass <-lmer(plant_height ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_height_species_ageClass)
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula:
mean_thickness ~ DroughtTrt * ageClass + (1 | DroughNet_plotID/plant_nr)
Data: lygra_data
REML criterion at convergence: -882.7
Scaled residuals:
Min 1Q Median 3Q Max
-3.1312 -0.3744 -0.0822 0.2949 4.1448
Random effects:
Groups Name Variance Std.Dev.
plant_nr:DroughNet_plotID (Intercept) 6.839e-03 8.270e-02
DroughNet_plotID (Intercept) 4.282e-12 2.069e-06
Residual 1.901e-03 4.360e-02
Number of obs: 351, groups:
plant_nr:DroughNet_plotID, 125; DroughNet_plotID, 12
Fixed effects:
Estimate Std. Error df t value
(Intercept) 0.23661 0.01519 122.10947 15.581
DroughtTrtExt (90) 0.03075 0.02307 120.99573 1.333
ageClassPioneer -0.00768 0.02143 121.18083 -0.358
DroughtTrtExt (90):ageClassPioneer -0.01550 0.03134 120.50134 -0.495
Pr(>|t|)
(Intercept) <2e-16 ***
DroughtTrtExt (90) 0.185
ageClassPioneer 0.721
DroughtTrtExt (90):ageClassPioneer 0.622
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Correlation of Fixed Effects:
(Intr) DrTE(90) agClsP
DrghtTE(90) -0.658
ageClassPnr -0.709 0.466
DrTE(90):CP 0.485 -0.736 -0.684
optimizer (nloptwrap) convergence code: 0 (OK)
boundary (singular) fit: see help('isSingular')
#plot and plant nr variance is 0#validate modelperformance::check_model(LY_thickness_droughtTrt_ageclass, detrend =FALSE)
anova(LY_thickness_droughtTrt_ageclass)
Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
DroughtTrt 0.0040959 0.0040959 1 120.5 2.1548 0.1447
ageClass 0.0018432 0.0018432 1 120.5 0.9697 0.3267
DroughtTrt:ageClass 0.0004649 0.0004649 1 120.5 0.2446 0.6218
three way interactions
LY_thickness_species__drought_ageClass <-lmer(mean_thickness ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_thickness_species__drought_ageClass)
# species * age Class (h2)tj_LDMC_species_ageClass <-lmer(LDMC ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_LDMC_species_ageClass)
Type III Analysis of Variance Table with Satterthwaite's method
Sum Sq Mean Sq NumDF DenDF F value Pr(>F)
species 1.93712 0.64571 3 122.323 353.2121 <2e-16 ***
DroughtTrt 0.00000 0.00000 1 8.134 0.0000 0.9967
ageClass 0.00152 0.00152 1 8.181 0.8297 0.3884
DroughtTrt:ageClass 0.00008 0.00008 1 8.133 0.0426 0.8416
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
young and old leaves (lygra)
# Subset the data for the specified species with young and old leaves, and for the Lygra sitesubset_data1 <-subset(droughtnet_data2_clean, species %in%c("Vaccinium vitis-idaea", "Empetrum nigrum") & siteID =="Lygra")# View the first few rows of the subsetted dataView(subset_data1)
LDMC
ldmc_three_way_interactions <-lmer(LDMC ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data1)summary(ldmc_three_way_interactions)
# Subset the data for the specified species with young and old leaves, and for the Lygra sitesubset_data2 <-subset(droughtnet_data2_clean, species %in%c("Vaccinium vitis-idaea", "Empetrum nigrum") & siteID =="Tjøtta")# View the first few rows of the subsetted dataView(subset_data2)
LDMC
ldmc1_three_way_interactions <-lmer(LDMC ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data2)summary(ldmc1_three_way_interactions)
# Create a data frame for Calluna vulgaris at the Lygra site and remove rows with NA valuescalluna_shoot <- droughtnet_data2_clean %>%filter(species =="Calluna vulgaris"& siteID =="Lygra") %>%drop_na()view(calluna_shoot)
---title: Analysisauthor: akformat: html: self-contained: true code-tools: true source: true fig-width: 10 fig-height: 6---```{r}#Load librarieslibrary(tidyverse)library(lme4)library(ggfortify)library(lmerTest)library(performance)library(readr)#install.packages("broom.mixed")library(broom.mixed)library(grid)``````{r}droughtnet <-read_csv("droughtnet_data_cleaned_final.csv", col_types =cols(calluna_shoot_type =col_factor(levels =c("Long", "Short"))),guess_max =Inf)View(droughtnet)# Now, to reorder the ageClass factor levels to start with Pioneerdroughtnet$ageClass <-factor(droughtnet$ageClass, levels =c("Mature", "Pioneer"))levels(droughtnet$ageClass)`````` ``````{r}droughtnet2 <- droughtnet %>%mutate(plant_nr =case_when(# For Calluna vulgaris under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Calluna vulgaris"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_CV_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Calluna vulgaris under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Calluna vulgaris"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_CV_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium myrtillus under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium myrtillus"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_VM_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium myrtillus under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium myrtillus"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_VM_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium vitis-idaea under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium vitis-idaea"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_VV_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Vaccinium vitis-idaea under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Vaccinium vitis-idaea"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_VV_Ext(90)_", DroughNet_plotID, "_", plant_nr),# For Empetrum nigrum under Amb (0) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Empetrum nigrum"& DroughtTrt =="Amb (0)"~paste0(siteID, "_", ageClass, "_EN_Amb(0)_", DroughNet_plotID, "_", plant_nr),# For Empetrum nigrum under Ext (90) treatment siteID %in%c("Lygra", "Tjøtta") & ageClass %in%c("Pioneer", "Mature") & species =="Empetrum nigrum"& DroughtTrt =="Ext (90)"~paste0(siteID, "_", ageClass, "_EN_Ext(90)_", DroughNet_plotID, "_", plant_nr),# Default case if none of the above conditions are metTRUE~as.character(plant_nr) ))view(droughtnet2)`````` ``````{r}``````{r}# Specify the columns to check for NA values# List of columns to check for NA valuescolumns_to_check <-c("DroughtTrt", "DroughNet_plotID", "ageClass", "siteID", "species", "plant_height", "SLA", "mean_thickness", "dry_mass_g_original", "LDMC", "leaf_area", "wet_mass_g", "dry_mass_g")# Check for rows with any NA values in the specified columnsna_rows <-apply(droughtnet2[columns_to_check], 1, function(row) any(is.na(row)))# Create a data frame showing how many NA values there are in each rowna_row_summary <- droughtnet2[na_rows, columns_to_check]na_row_summary$row_na_count <-rowSums(is.na(na_row_summary))# Summarize the number of rows by the count of NAs they containna_row_summary <- na_row_summary %>%group_by(row_na_count) %>%summarise(n =n(), .groups ='drop')# Create a summary showing the co-occurrence of NA values across the specified columnsna_co_occurrence <- droughtnet2 %>%summarise(across(all_of(columns_to_check), ~sum(is.na(.)))) %>%pivot_longer(cols =everything(), names_to ="variable", values_to ="na_count") %>%arrange(desc(na_count))# Print the summariesprint(paste("Total rows with any NA values across checked columns:", sum(na_rows)))print(na_row_summary)print(na_co_occurrence)``````{r}# Create the new data frame with selected columnsdroughtnet_data2 <-select(droughtnet2, "envelope_ID", "siteID", "species", "ageClass", "DroughtTrt", "DroughNet_plotID", "leaf_age", "calluna_shoot_type", "plant_height", "mean_thickness", "SLA", "LDMC", "plant_nr")view(droughtnet_data2)# Specify the columns to check for NA valuescolumns_to_check2 <-c("plant_height", "mean_thickness", "SLA", "LDMC")# Remove rows with any NA values in the specified columnsdroughtnet_data2_clean <- droughtnet_data2[!rowSums(is.na(droughtnet_data2[columns_to_check2])), ]view(droughtnet_data2_clean)# Calculate the total number of NAs removed (for the specified columns only)# This calculation considers rows removed rather than individual NAstotal_NAs_removed <-nrow(droughtnet_data2) -nrow(droughtnet_data2_clean)# Calculate the total number of entries remainingtotal_entries_remaining <-nrow(droughtnet_data2_clean)# Print out the total NAs removed and total entries remainingcat("Total NAs removed:", total_NAs_removed, "\n")cat("Total entries remaining:", total_entries_remaining, "\n")```**Analysis for young leaves**```{r}# Specify the species of interest, including Calluna vulgarisspecies_of_interest <-c("Empetrum nigrum", "Vaccinium myrtillus", "Vaccinium vitis-idaea", "Calluna vulgaris")# Filter the data to include only the specified species where leaf_age is 'young',# and for Calluna vulgaris, additionally check that calluna_shoot_type is 'short'filtered_data <- droughtnet_data2_clean %>%filter(species %in% species_of_interest, leaf_age =="young") %>%filter(# Include Calluna vulgaris from Tjøtta regardless of calluna_shoot_type (species =="Calluna vulgaris"& siteID =="Tjøtta") |# Include Calluna vulgaris from Lygra only if calluna_shoot_type is Short (species =="Calluna vulgaris"& siteID =="Lygra"& calluna_shoot_type =="Short") |# Include other species of interest from both sites (species !="Calluna vulgaris") )view(filtered_data)``````{r}p <-ggplot(filtered_data, aes(x =as.factor(plant_nr), y = mean_thickness, color = DroughtTrt)) +geom_point() +# Use geom_point for individual observationsfacet_wrap(~ ageClass + siteID, scales ="free", nrow =2) +# Adjusted for clearer separationtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="thickness Response to Treatment",x ="Plant Number",y ="thickness", # Assuming height is in centimeterscolor ="Drought Treatment") # Adjusted labelggsave("thickness_plot.png", plot = p, width =10, height =8, dpi =300)```**plots****plant height**```{r}filtered_data <- filtered_data %>%filter(siteID %in%c("Tjøtta", "Lygra"), DroughtTrt %in%c("Amb (0)", "Ext (90)"), ageClass %in%c("Pioneer", "Mature"))ggplot(filtered_data, aes(x = species, y = plant_height, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +# Removed leaf_age from facet_gridtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="Plant Height vs Treatment by Species for Young Leaves",x ="Species",y ="Plant Height") +scale_fill_manual(values =c("Amb (0)"="blue", "Ext (90)"="grey")) # Assigning colors to treatments```**SLA**```{r}ggplot(filtered_data, aes(x = species, y =log(SLA), fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="SLA vs Treatment by Species",x ="Species",y ="Log (SLA)",fill ="Drought Treatment",caption ="Figure 2: SLA Variation in Dwarf Shrubs Under Drought Conditions Across Different Ages and Sites") +scale_fill_manual(values =c("Amb (0)"="orange", "Ext (90)"="darkgrey")) # Assigning colors to treatments```**LDMC**```{r}ggplot(filtered_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in dwarf Shrubs Under drought conditions across different successional phases and sites") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue")) # Assigning colors to treatments#trying using jitter for the graphsggplot(filtered_data, aes(x = species, y = LDMC, color = DroughtTrt)) +geom_jitter(position =position_dodge(width =0.5), size =1.5, alpha =0.7) +# Use position_dodge to separate pointsfacet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # Vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",color ="Drought Treatment", # Updated from fill to colorcaption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases and Sites") +scale_color_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="red")) # Assigning colors to treatments```**Mean_thickness**```{r}filtered_data <- filtered_data %>%filter(siteID %in%c("Tjøtta", "Lygra"), DroughtTrt %in%c("Amb (0)", "Ext (90)"), ageClass %in%c("Pioneer", "Mature"))ggplot(filtered_data, aes(x = species, y = mean_thickness, fill = DroughtTrt)) +geom_boxplot() +facet_grid(ageClass ~ siteID, scales ="free") +# Removed leaf_age from facet_gridtheme_bw() +theme(axis.text.x =element_text(angle =90, hjust =1)) +labs(title ="Plant Height vs Treatment by Species for Young Leaves",x ="Species",y ="mean_thickness") +scale_fill_manual(values =c("Amb (0)"="blue", "Ext (90)"="grey")) # Assigning colors to treatments```**Analysis for lygra site****filter data only for lygra**```{r}# Filter the data for siteID Lygralygra_data <- filtered_data %>%filter(siteID =="Lygra")view(lygra_data)```**`Trait 1- LDMC- models`**```{r}lygra_data$plant_nr <-as.factor(lygra_data$plant_nr)# fitting a linear mixed-effects model using lmer, plant nr is the nested random effect# Ensure variables are treated as categorical if they represent categorieslygra_data$plant_nr <-as.factor(lygra_data$plant_nr)# Model with all the main effects for LDMCLY_model_main_effects_LDMC <-lmer(LDMC ~ species + DroughtTrt + ageClass + (1| DroughNet_plotID/plant_nr),data = lygra_data)summary(LY_model_main_effects_LDMC)#validate modelperformance::check_model(LY_model_main_effects_LDMC, detrend =FALSE)view(lygra_data)# Extract coefficients to a data frame```**2-way interactions**```{r}#species * DroughtTrtLY_LDMC_species_droughtTrt <-lmer(LDMC ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_LDMC_species_droughtTrt )#validate modelperformance::check_model(LY_LDMC_species_droughtTrt, detrend =FALSE)``````{r}#blme package- install#install.packages("blme")library(blme)model <-blmer(LDMC ~ species * DroughtTrt + (1| DroughNet_plotID), data = lygra_data)# Examine the summary of the modelsummary(model)names(lygra_data)```**plot model onto the ggplot**```{r}ggplot(lygra_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +facet_grid(~ ageClass, scales ="free") +# Facet only by ageClasstheme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +# Center the captionlabs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue"))#fit model# Get fitted values directly from the modelfitted_values <-predict(LY_LDMC_species_droughtTrt, re.form =NA) lygra_data$fitted <- fitted_values# Assuming fitted_values has been added to filtered_data as shown aboveggplot(lygra_data, aes(x = species, y = LDMC, fill = DroughtTrt)) +geom_boxplot() +geom_point(aes(y = fitted), position =position_dodge(width =0.75), color ="red", size =1.5) +# Add fitted valuesfacet_grid(~ ageClass, scales ="free") +# Facet only by ageClasstheme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1), # Vertical adjustment for x axis labelsplot.caption =element_text(hjust =0.5)) +labs(title ="LDMC vs Treatment by Species",x ="Species",y ="LDMC",fill ="Drought Treatment",caption ="Figure 3: LDMC Variation in Dwarf Shrubs Under Drought Conditions Across Different Successional Phases") +scale_fill_manual(values =c("Amb (0)"="darkblue", "Ext (90)"="lightblue"))#fiiting in the geom jitter plot# Get fitted values directly from the modelfitted_values <-predict(LY_LDMC_species_droughtTrt, re.form =NA) # Assuming 'fitted_values' is a vector of the same length as 'lygra_data'lygra_data$fitted <- fitted_valuesfitted_values$dodge_position <-as.numeric(lygra_data$DroughtTrt) -1.5ggplot(lygra_data, aes(x = species, y = LDMC, group = DroughtTrt)) +geom_jitter(aes(color = DroughtTrt), position =position_dodge(width =0.5), size =1.5, alpha =0.7) +geom_point(aes(y = fitted, color = DroughtTrt), # Ensure 'fitted' is now recognizedposition =position_dodge(width =0.5), size =3, shape =16, color ="black") +facet_grid(ageClass ~ siteID, scales ="free") +theme_bw() +theme(axis.text.x =element_text(angle =90, vjust =0.5, hjust =1)) +labs(title ="LDMC vs Treatment by Species", x ="Species", y ="LDMC", color ="Drought Treatment") +scale_color_manual(values =c("Amb (0)"="darkgreen", "Ext (90)"="deeppink"))``````{r}# species * age Class (h2)xxx#this will help adress the hypothesis by examining weather the effect of drought on trait varies between age classes#significant interaction supports the hypothesis that mat and pio respond differently to droght conditions, potentially more consrvative traits in mat than pioLY_LDMC_species_ageClass <-lmer(LDMC ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_LDMC_species_ageClass)#validate modelperformance::check_model(LY_LDMC_species_ageClass, detrend =FALSE)``````{r}#xxxxxLY_droughtTrt_ageclass <-lmer(LDMC ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_droughtTrt_ageclass)#plot variance zero#validate modelperformance::check_model(LY_droughtTrt_ageclass, detrend =FALSE)```**3-way interaction**```{r}LY_LDMC_species__drought_ageClass <-lmer(LDMC ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_LDMC_species__drought_ageClass)#validate modelperformance::check_model(LY_LDMC_species__drought_ageClass, detrend =FALSE)```**Trait 2- SLA**```{r}#species * DroughtTrtLY_SLA_species_droughtTrt <-lmer(log(SLA) ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_SLA_species_droughtTrt)#validate modelperformance::check_model(LY_SLA_species_droughtTrt , detrend =FALSE)``````{r}# species * age Class xxxxxxLY_SLA_species_ageClass <-lmer(log(SLA) ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_SLA_species_ageClass)#zero variance#validate modelperformance::check_model(LY_SLA_species_ageClass, detrend =FALSE)anova(LY_SLA_species_ageClass)``````{r}#xxxxxLY_SLA_droughtTrt_ageclass <-lmer(log(SLA) ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_SLA_droughtTrt_ageclass)#plot variance is zero#validate modelperformance::check_model(LY_SLA_droughtTrt_ageclass, detrend =FALSE)anova(LY_SLA_droughtTrt_ageclass)``````{r}#xxxxLY_SLA_species__drought_ageClass <-lmer(log(SLA) ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_SLA_species__drought_ageClass)#plot variance is zero#validate modelperformance::check_model(LY_SLA_species__drought_ageClass, detrend =FALSE)anova(LY_SLA_species__drought_ageClass)```**Trait 3: plant height**```{r}#species * DroughtTrtLY_height_species_droughtTrt <-lmer(plant_height ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_height_species_droughtTrt)#validate modelperformance::check_model(LY_height_species_droughtTrt , detrend =FALSE)anova(LY_height_species_droughtTrt)``````{r}# species * age Class (h2)LY_height_species_ageClass <-lmer(plant_height ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_height_species_ageClass)#validate modelperformance::check_model(LY_height_species_ageClass, detrend =FALSE)anova(LY_height_species_ageClass)``````{r}#xxxxLY_height_droughtTrt_ageclass <-lmer(plant_height ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_height_droughtTrt_ageclass)# failed to converge#validate modelperformance::check_model(LY_height_droughtTrt_ageclass, detrend =FALSE)anova(LY_height_droughtTrt_ageclass)``````{r}LY_height_species__drought_ageClass <-lmer(plant_height ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_height_species__drought_ageClass)#validate modelperformance::check_model(LY_height_species__drought_ageClass, detrend =FALSE)anova(LY_height_species__drought_ageClass)```**Trait 4: mean -thickness**```{r}#species * DroughtTrt#xxxxLY_thickness_species_droughtTrt <-lmer(mean_thickness ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_thickness_species_droughtTrt)#plot variance is zero#validate modelperformance::check_model(LY_thickness_species_droughtTrt , detrend =FALSE)``````{r}# species * age Class xxxLY_thickness_species_ageClass <-lmer(mean_thickness ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_thickness_species_ageClass)#validate modelperformance::check_model(LY_thickness_species_ageClass, detrend =FALSE)``````{r}#xxxxLY_thickness_droughtTrt_ageclass <-lmer(mean_thickness ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_thickness_droughtTrt_ageclass)#plot and plant nr variance is 0#validate modelperformance::check_model(LY_thickness_droughtTrt_ageclass, detrend =FALSE)anova(LY_thickness_droughtTrt_ageclass)```**three way interactions**```{r}LY_thickness_species__drought_ageClass <-lmer(mean_thickness ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = lygra_data)summary(LY_thickness_species__drought_ageClass)#the model is okak, but very small variability#validate modelperformance::check_model(LY_thickness_species__drought_ageClass, detrend =FALSE)anova(LY_thickness_species__drought_ageClass)```**site: Tjøtta**```{r}# Filter the data for siteID tjøttatjøtta_data <- filtered_data %>%filter(siteID =="Tjøtta")view(tjøtta_data)```**trait 1- LDMC**```{r}tj_LDMC_species_ageClass <-lmer(LDMC ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_LDMC_species_ageClass)performance::check_model(tj_LDMC_species_ageClass, detrend =FALSE)``````{r}# species * age Class (h2)tj_LDMC_species_ageClass <-lmer(LDMC ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_LDMC_species_ageClass)#validate modelperformance::check_model(tj_LDMC_species_ageClass, detrend =FALSE)``````{r}tj_LDMC_drought_ageClass <-lmer(LDMC ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_LDMC_drought_ageClass)#validate modelperformance::check_model(tj_LDMC_drought_ageClass, detrend =FALSE)```**three way**```{r}tj_LDMC_species__drought_ageClass <-lmer(LDMC ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_LDMC_species__drought_ageClass)#validate modelperformance::check_model(tj_LDMC_species__drought_ageClass, detrend =FALSE)anova(tj_LDMC_species__drought_ageClass)```**Trait- plant height**```{r}tj_height_species_drought <-lmer(log(plant_height) ~ species * DroughtTrt + (1| DroughNet_plotID), data = tjøtta_data)summary(tj_height_species_drought)performance::check_model(tj_height_species_drought, detrend =FALSE)``````{r}tj_height_species_ageClass <-lmer(log(plant_height) ~ species * ageClass + (1| DroughNet_plotID), data = tjøtta_data)summary(tj_height_species_ageClass)performance::check_model(tj_height_species_ageClass, detrend =FALSE)``````{r}tj_height_drought_ageClass <-lmer(log(plant_height) ~ DroughtTrt * ageClass + (1| DroughNet_plotID), data = tjøtta_data)summary(tj_height_drought_ageClass)#validate modelperformance::check_model(tj_height_drought_ageClass, detrend =FALSE)```**three way**```{r}tj_height_species_drought_ageClass <-lmer(log(plant_height) ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID), data = tjøtta_data)summary(tj_height_species_drought_ageClass)#validate modelperformance::check_model(tj_height_species_drought_ageClass, detrend =FALSE)anova(tj_LDMC_species__drought_ageClass)```**trait2 - SLA**```{r}tj_sla_species_drought <-lmer(log(SLA) ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_sla_species_drought)performance::check_model(tj_sla_species_drought, detrend =FALSE)``````{r}tj_sla_species_ageClass <-lmer(log(SLA) ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_sla_species_ageClass)performance::check_model(tj_sla_species_ageClass, detrend =FALSE)``````{r}#xxxtj_sla_drought_ageClass <-lmer(log(SLA) ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_sla_drought_ageClass)#validate modelperformance::check_model(tj_sla_drought_ageClass, detrend =FALSE)```**three way**```{r}tj_sla_species__drought_ageClass <-lmer(log(SLA) ~ species * DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_sla_species__drought_ageClass)#validate modelperformance::check_model(tj_sla_species__drought_ageClass, detrend =FALSE)anova(tj_sla_species__drought_ageClass)```**trait 4: mean thickness**```{r}tj_thickness_species_drought <-lmer(mean_thickness ~ species * DroughtTrt + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_thickness_species_drought)performance::check_model(tj_thickness_species_drought, detrend =FALSE)``````{r}tj_thickness_species_ageClass <-lmer(mean_thickness ~ species * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_thickness_species_ageClass)performance::check_model(tj_thickness_species_ageClass, detrend =FALSE)``````{r}#xxxtj_thickness_drought_ageClass <-lmer(mean_thickness ~ DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_thickness_drought_ageClass)#validate modelperformance::check_model(tj_thickness_drought_ageClass, detrend =FALSE)```**three way**```{r}tj_thickness_species_drought_ageClass <-lmer(mean_thickness ~ species + DroughtTrt * ageClass + (1| DroughNet_plotID/plant_nr), data = tjøtta_data)summary(tj_thickness_species_drought_ageClass)#validate modelperformance::check_model(tj_thickness_species_drought_ageClass, detrend =FALSE)anova(tj_thickness_species_drought_ageClass)```**young and old leaves (lygra)**```{r}# Subset the data for the specified species with young and old leaves, and for the Lygra sitesubset_data1 <-subset(droughtnet_data2_clean, species %in%c("Vaccinium vitis-idaea", "Empetrum nigrum") & siteID =="Lygra")# View the first few rows of the subsetted dataView(subset_data1)```**LDMC**```{r}ldmc_three_way_interactions <-lmer(LDMC ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data1)summary(ldmc_three_way_interactions)performance::check_model(ldmc_three_way_interactions, detrend =FALSE)```**SLA**```{r}sla_three_way_interactions <-lmer(log(SLA) ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data1)summary(sla_three_way_interactions)performance::check_model(sla_three_way_interactions, detrend =FALSE)anova(sla_three_way_interactions)```**mean thickness**```{r}thickness_three_way_interactions <-lmer(mean_thickness ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data1)summary(thickness_three_way_interactions)performance::check_model(thickness_three_way_interactions, detrend =FALSE)```**young and old leaves (tjøtta)**```{r}# Subset the data for the specified species with young and old leaves, and for the Lygra sitesubset_data2 <-subset(droughtnet_data2_clean, species %in%c("Vaccinium vitis-idaea", "Empetrum nigrum") & siteID =="Tjøtta")# View the first few rows of the subsetted dataView(subset_data2)```**LDMC**```{r}ldmc1_three_way_interactions <-lmer(LDMC ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data2)summary(ldmc1_three_way_interactions)performance::check_model(ldmc1_three_way_interactions, detrend =FALSE)```**SLA**```{r}sla2_three_way_interactions <-lmer(log(SLA) ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data2)summary(sla2_three_way_interactions)performance::check_model(sla2_three_way_interactions, detrend =FALSE)```**mean thickness**```{r}thickness3_three_way_interactions <-lmer(mean_thickness ~ species * DroughtTrt * leaf_age + (1| DroughNet_plotID/plant_nr), data = subset_data2)summary(thickness3_three_way_interactions)performance::check_model(thickness3_three_way_interactions, detrend =FALSE)```**CALLUNA SHOOT TYPE (lygra)**```{r}# Create a data frame for Calluna vulgaris at the Lygra site and remove rows with NA valuescalluna_shoot <- droughtnet_data2_clean %>%filter(species =="Calluna vulgaris"& siteID =="Lygra") %>%drop_na()view(calluna_shoot)```**LDMC**```{r}shoot_type_lmdc3 <-lmer(LDMC ~ (calluna_shoot_type * DroughtTrt * ageClass) + (1| DroughNet_plotID/plant_nr), data = calluna_shoot)summary(shoot_type_lmdc3)performance::check_model(shoot_type_lmdc3, detrend =FALSE)```**SLA**```{r}shoot_type_sla3 <-lmer(log(SLA) ~ (calluna_shoot_type * DroughtTrt * ageClass) + (1| DroughNet_plotID/plant_nr), data = calluna_shoot)summary(shoot_type_sla3)performance::check_model(shoot_type_sla3, detrend =FALSE)```**mean thickness**```{r}shoot_type_thickness3 <-lmer(mean_thickness ~ (calluna_shoot_type * DroughtTrt * ageClass) + (1| DroughNet_plotID/plant_nr), data = calluna_shoot)summary(shoot_type_thickness3)performance::check_model(shoot_type_thickness3, detrend =FALSE)```